local gaiLianying = fk.CreateSkill({
    name = "gai__lianying",
  })
  
  Fk:loadTranslationTable{
    ["gai__lianying"] = "连营",
    [":gai__lianying"] = "其他角色的回合结束时，你可以观看牌堆顶X张牌，然后将这些牌分配给任意角色（X为你本回合失去过的牌数，且至多为3）。",
  
    ["$gai__lianying1"] = "蜀营连绵百里，正待吾燎原一炬！",
    ["$gai__lianying2"] = "蜀军虚实已知，吾等不日便破也！",
  }
  
  gaiLianying:addEffect(fk.TurnEnd, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
      return
        target ~= player and
        player:hasSkill(gaiLianying.name) and
        #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
          for _, move in ipairs(e.data) do
            if
              move.from == player and
              not (move.to == player and (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip))
            then
              return
                table.find(
                  move.moveInfo,
                  function(info) return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip end
                ) ~= nil
            end
          end
  
          return false
        end, Player.HistoryTurn) > 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local sum = 0
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if
            move.from == player and
            not (move.to == player and (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip))
          then
            sum = sum + #table.filter(
              move.moveInfo,
              function(info) return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip end
            )
  
            if sum > 2 then
              return true
            end
          end
        end
  
        return false
      end, Player.HistoryTurn)
  
      sum = math.min(sum, 3)
      local ids = room:getNCards(sum)
      room:askToYiji(player, { min_num = sum, max_num = sum, cards = ids, skill_name = gaiLianying.name, expand_pile = ids })
    end,
  })
  
  return gaiLianying